home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / BARNET / ARMTEX / SOURCES1 / !TeX / texmf / source / armTeX / TeX / tex / ch < prev   
Encoding:
Text File  |  1998-04-05  |  75.5 KB  |  2,137 lines

  1. % tex.ch for C compilation with web2c, derived from various other change files.
  2. % By Tim Morgan, UC Irvine ICS Department, and many others.
  3. %
  4. % Modification history:
  5. % (05/28/86) ETM Started with TeX 2.0
  6. % (06/03/87) ETM Brought up to TeX 2.2
  7. % (09/26/87) ETM Brought up to TeX 2.3
  8. % (10/01/87) ETM Brought up to TeX 2.5
  9. % (12/21/87) ETM Brought up to TeX 2.7
  10. % (01/14/88) ETM Brought up to TeX 2.9
  11. % (02/20/88) PAM Revised format and module numbers
  12. % (03/01/88) ETM Eliminated some unused variables and unnecesary tests
  13. % (05/09/88) ETM Added yet another casting bug fix
  14. % (06/21/88) ETM Brought up to TeX version 2.93
  15. % (12/11/88) ETM Brought up to TeX version 2.94
  16. % (01/12/89) PAM Brought up to TeX version 2.95
  17. % (02/14/89) ETM Brought up to TeX version 2.96
  18. % (03/10/89) ETM Brought up to TeX version 2.98
  19. % (07/06/89) ETM Brought up to TeX version 2.991
  20. % (11/30/89) KB  To version 2.992 (8-bit).
  21. % (01/10/90) SR  To version 2.993.
  22. % (03/27/90) KY  To version 3.0.
  23. % (more recent changes in ChangeLog)
  24. % The module numbers in this change file refer to the published text in
  25. % TeX: The Program, Volume B of Computers&Typesetting.
  26.  
  27.  
  28. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  29. % [0] WEAVE: print changes only.
  30. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  31. @x
  32.   \def\?##1]{\hbox to 1in{\hfil##1.\ }}
  33.   }
  34. @y
  35.   \def\?##1]{\hbox{Changes to \hbox to 1em{\hfil##1}.\ }}
  36.   }
  37. \let\maybe=\iffalse
  38. @z
  39.  
  40. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  41. % [1.2] banner
  42. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43. @x
  44. @d banner=='This is TeX, Version 3.14159' {printed when \TeX\ starts}
  45. @y
  46. @d banner=='This is big armTeX 3.14159'
  47. @z
  48.  
  49. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  50. % [1.4] program header
  51. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  52. @x
  53. Actually the heading shown here is not quite normal: The |program| line
  54. does not mention any |output| file, because \ph\ would ask the \TeX\ user
  55. to specify a file name if |output| were specified here.
  56. @^system dependencies@>
  57.  
  58. @d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
  59. @f mtype==type {`\&{mtype}' will be equivalent to `\&{type}'}
  60. @f type==true {but `|type|' will not be treated as a reserved word}
  61.  
  62. @p @t\4@>@<Compiler directives@>@/
  63. program TEX; {all file names are defined dynamically}
  64. label @<Labels in the outer block@>@/
  65. @y
  66.  
  67. @d mtype==t@&y@&p@&e {this is a \.{WEB} coding trick:}
  68. @f mtype==type {`\&{mtype}' will be equivalent to `\&{type}'}
  69. @f type==true {but `|type|' will not be treated as a reserved word}
  70.  
  71. @p @t\4@>@<Compiler directives@>@/
  72. program TEX; {all file names are defined dynamically}
  73. @z
  74.  
  75. @x
  76. @<Labels in the out...@>=
  77. start_of_TEX@t\hskip-2pt@>, end_of_TEX@t\hskip-2pt@>,@,final_end;
  78.   {key control points}
  79. @y
  80. @<Labels in the outer block@>=
  81. start_of_TEX@t\hskip-2pt@>, end_of_TEX@t\hskip-2pt@>,@,final_end;
  82.   {key control points}
  83. @z
  84.  
  85. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  86. % [1.7] debug..gubed, stat..tats
  87. % Here we change these WEB symbols, which are used much as #ifdef's
  88. % are in C, into something which will get translated into actual #ifdef's.
  89. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90. @x
  91. @d debug==@{ {change this to `$\\{debug}\equiv\null$' when debugging}
  92. @d gubed==@t@>@} {change this to `$\\{gubed}\equiv\null$' when debugging}
  93. @y
  94. @d debug==ifdef('DEBUG')
  95. @d gubed==endif('DEBUG')
  96. @z
  97. @x
  98. @d stat==@{ {change this to `$\\{stat}\equiv\null$' when gathering
  99.   usage statistics}
  100. @d tats==@t@>@} {change this to `$\\{tats}\equiv\null$' when gathering
  101.   usage statistics}
  102. @y
  103. @d stat==ifdef('STAT')
  104. @d tats==endif('STAT')
  105. @z
  106.  
  107. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  108. % [1.8] Same, for `init..tini'.
  109. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  110. @x
  111. @d init== {change this to `$\\{init}\equiv\.{@@\{}$' in the production version}
  112. @d tini== {change this to `$\\{tini}\equiv\.{@@\}}$' in the production version}
  113. @y
  114. @d init==ifdef('INITEX')
  115. @d tini==endif('INITEX')
  116. @z
  117.  
  118. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  119. % [1.9] Turn off all compiler directives.
  120. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  121. @x
  122. @{@&$C-,A+,D-@} {no range check, catch arithmetic overflow, no debug overhead}
  123. @!debug @{@&$C+,D+@}@+ gubed {but turn everything on when debugging}
  124. @y
  125. @z
  126.  
  127. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  128. % [1.11] Compile-time constants: some enlarged, dvi_buf_size 16K for
  129. % BSD I/O, file_name_size is set from the system constant.
  130. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  131. @x
  132. @<Constants...@>=
  133. @!mem_max=30000; {greatest index in \TeX's internal |mem| array;
  134.   must be strictly less than |max_halfword|;
  135.   must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|}
  136. @!mem_min=0; {smallest index in \TeX's internal |mem| array;
  137.   must be |min_halfword| or more;
  138.   must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|}
  139. @!buf_size=500; {maximum number of characters simultaneously present in
  140.   current lines of open files and in control sequences between
  141.   \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|}
  142. @!error_line=72; {width of context lines on terminal error messages}
  143. @!half_error_line=42; {width of first lines of contexts in terminal
  144.   error messages; should be between 30 and |error_line-15|}
  145. @!max_print_line=79; {width of longest text lines output; should be at least 60}
  146. @!stack_size=200; {maximum number of simultaneous input sources}
  147. @!max_in_open=6; {maximum number of input files and error insertions that
  148.   can be going on simultaneously}
  149. @!font_max=75; {maximum internal font number; must not exceed |max_quarterword|
  150.   and must be at most |font_base+256|}
  151. @!font_mem_size=20000; {number of words of |font_info| for all fonts}
  152. @!param_size=60; {maximum number of simultaneous macro parameters}
  153. @!nest_size=40; {maximum number of semantic levels simultaneously active}
  154. @!max_strings=3000; {maximum number of strings; must not exceed |max_halfword|}
  155. @!string_vacancies=8000; {the minimum number of characters that should be
  156.   available for the user's control sequences and font names,
  157.   after \TeX's own error messages are stored}
  158. @!pool_size=32000; {maximum number of characters in strings, including all
  159.   error messages and help texts, and the names of all fonts and
  160.   control sequences; must exceed |string_vacancies| by the total
  161.   length of \TeX's own strings, which is currently about 23000}
  162. @!save_size=600; {space for saving values outside of current group; must be
  163.   at most |max_halfword|}
  164. @!trie_size=8000; {space for hyphenation patterns; should be larger for
  165.   \.{INITEX} than it is in production versions of \TeX}
  166. @!trie_op_size=500; {space for ``opcodes'' in the hyphenation patterns}
  167. @!dvi_buf_size=800; {size of the output buffer; must be a multiple of 8}
  168. @!file_name_size=40; {file names shouldn't be longer than this}
  169. @!pool_name='TeXformats:TEX.POOL                     ';
  170.   {string of length |file_name_size|; tells where the string pool appears}
  171. @y
  172. @d file_name_size == PATH_MAX
  173.  
  174. @<Constants...@>=
  175. @!mem_max=262140; {greatest index in \TeX's internal |mem| array;
  176.   must be strictly less than |max_halfword|;
  177.   must be equal to |mem_top| in \.{INITEX}, otherwise |>=mem_top|}
  178. @!mem_min=0; {smallest index in \TeX's internal |mem| array;
  179.   must be |min_halfword| or more;
  180.   must be equal to |mem_bot| in \.{INITEX}, otherwise |<=mem_bot|}
  181. @!buf_size=3000; {maximum number of characters simultaneously present in
  182.   current lines of open files and in control sequences between
  183.   \.{\\csname} and \.{\\endcsname}; must not exceed |max_halfword|}
  184. @!error_line=72; {width of context lines on terminal error messages}
  185. @!half_error_line=45; {width of first lines of contexts in terminal
  186.   error messages; should be between 30 and |error_line-15|}
  187. @!max_print_line=72; {width of longest text lines output; should be at least 60}
  188. @!stack_size=300; {maximum number of simultaneous input sources}
  189. @!max_in_open=15; {maximum number of input files and error insertions that
  190.   can be going on simultaneously}
  191. @!font_max=255; {maximum internal font number; must not exceed |max_quarterword|
  192.   and must be at most |font_base+256|}
  193. @!font_mem_size=100000; {number of words of |font_info| for all fonts}
  194. @!param_size=60; {maximum number of simultaneous macro parameters}
  195. @!nest_size=40; {maximum number of semantic levels simultaneously active}
  196. @!max_strings=15000; {maximum number of strings; must not exceed |max_halfword|}
  197. @!string_vacancies=100000; {the minimum number of characters that should be
  198.   available for the user's control sequences and font names,
  199.   after \TeX's own error messages are stored}
  200. @!pool_size=124000; {maximum number of characters in strings, including all
  201.   error messages and help texts, and the names of all fonts and
  202.   control sequences; must exceed |string_vacancies| by the total
  203.   length of \TeX's own strings, which is currently about 23000}
  204. @!save_size=4000; {space for saving values outside of current group; must be
  205.   at most |max_halfword|}
  206. @!trie_size=30000; {space for hyphenation patterns; should be larger for
  207.   \.{INITEX} than it is in production versions of \TeX.  This much is
  208.   needed for English, German, and Portuguese.}
  209. @!trie_op_size=751; {space for ``opcodes'' in the hyphenation patterns;
  210.   should be relatively prime to 313, 361, and 1009, and prime.}
  211. @!neg_trie_op_size=-751; {for lower |trie_op_hash| array bound;
  212.   must be equal to |-trie_op_size|.}
  213. @!min_trie_op=0; {first possible trie op code for any language}
  214. @!max_trie_op=500; {largest possible trie op code for any language}
  215. @!dvi_buf_size=8192; {size of the output buffer; must be a multiple of 8}
  216. @!pool_name=TEX_POOL_NAME; {name comes from \.{site.h}.}
  217.   {string of length |file_name_size|; tells where the string pool appears}
  218. @!mem_top=262140; {largest index in the |mem| array dumped by \.{INITEX};
  219.   must be substantially larger than |mem_bot|,
  220.   equal to |mem_max| in \.{INITEX}, else not greater than |mem_max|}
  221. @z
  222.  
  223. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  224. % [1.12] Sensitive compile-time constants.  For C we change mem_base and
  225. % hi_mem_base to reflect our use of 0-origin vs pc's use of
  226. % negative-origin.  Despite the fact that it is a ``sensitive''
  227. % constant, we're going to make mem_top a #define in the C code for
  228. % readability and ease of modification (it's up above) -- it needs
  229. % to be changed for the trip test.
  230. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  231. @x
  232. @d mem_bot=0 {smallest index in the |mem| array dumped by \.{INITEX};
  233.   must not be less than |mem_min|}
  234. @d mem_top==30000 {largest index in the |mem| array dumped by \.{INITEX};
  235.   must be substantially larger than |mem_bot|
  236.   and not greater than |mem_max|}
  237. @d font_base=0 {smallest internal font number; must not be less
  238.   than |min_quarterword|}
  239. @d hash_size=2100 {maximum number of control sequences; it should be at most
  240.   about |(mem_max-mem_min)/10|}
  241. @d hash_prime=1777 {a prime number equal to about 85\pct! of |hash_size|}
  242. @d hyph_size=307 {another prime; the number of \.{\\hyphenation} exceptions}
  243. @y
  244. @d mem_bot=0 {smallest index in the |mem| array dumped by \.{INITEX};
  245.   must not be less than |mem_min|}
  246. @d font_base=0 {smallest internal font number; must not be less
  247.   than |min_quarterword|}
  248. @d hash_size=9500 {maximum number of control sequences; it should be at most
  249.   about |(mem_max-mem_min)/10|}
  250. @d hash_prime=7919 {a prime number equal to about 85\pct! of |hash_size|}
  251. @d hyph_size=607 {another prime; the number of \.{\\hyphenation} exceptions}
  252. @z
  253.  
  254. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  255. % [1.16] Use C macros for `incr' and `decr'.
  256. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  257. @x
  258. @d incr(#) == #:=#+1 {increase a variable by unity}
  259. @d decr(#) == #:=#-1 {decrease a variable by unity}
  260. @y
  261. @z
  262.  
  263. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  264. % [??] The text_char type is used as an array index into xord.  The
  265. % default type `char' produces signed integers, which are bad array
  266. % indices in C.
  267. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  268. @x
  269. @d text_char == char {the data type of characters in text files}
  270. @y
  271. @d text_char == ASCII_code {the data type of characters in text files}
  272. @z
  273.  
  274. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  275. % [2.23] Allow any character as input.
  276. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  277. @x
  278. for i:=0 to @'37 do xchr[i]:=' ';
  279. for i:=@'177 to @'377 do xchr[i]:=' ';
  280. @y
  281. for i:=0 to @'37 do xchr[i]:=chr(i);
  282. for i:=@'177 to @'377 do xchr[i]:=chr(i);
  283. @z
  284.  
  285. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  286. % [3.25] Remove file types we don't need.
  287. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  288. @x
  289. The program actually makes use also of a third kind of file, called a
  290. |word_file|, when dumping and reloading base information for its own
  291. initialization.  We shall define a word file later; but it will be possible
  292. for us to specify simple operations on word files before they are defined.
  293.  
  294. @y
  295. I/O in C is done using standard I/O.  We will define the path numbers
  296. in an include file for C which are used in searching for files to be
  297. read.  We'll define all the file types in C also.
  298. @z
  299.  
  300. @x
  301. @!alpha_file=packed file of text_char; {files that contain textual data}
  302. @!byte_file=packed file of eight_bits; {files that contain binary data}
  303. @y
  304. @z
  305.  
  306. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  307. % [3.27] Do file opening in C.
  308. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  309. @x
  310. @ The \ph\ compiler with which the present version of \TeX\ was prepared has
  311. extended the rules of \PASCAL\ in a very convenient way. To open file~|f|,
  312. we can write
  313. $$\vbox{\halign{#\hfil\qquad&#\hfil\cr
  314. |reset(f,@t\\{name}@>,'/O')|&for input;\cr
  315. |rewrite(f,@t\\{name}@>,'/O')|&for output.\cr}}$$
  316. The `\\{name}' parameter, which is of type `{\bf packed array
  317. $[\langle\\{any}\rangle]$ of \\{char}}', stands for the name of
  318. the external file that is being opened for input or output.
  319. Blank spaces that might appear in \\{name} are ignored.
  320.  
  321. The `\.{/O}' parameter tells the operating system not to issue its own
  322. error messages if something goes wrong. If a file of the specified name
  323. cannot be found, or if such a file cannot be opened for some other reason
  324. (e.g., someone may already be trying to write the same file), we will have
  325. |@!erstat(f)<>0| after an unsuccessful |reset| or |rewrite|.  This allows
  326. \TeX\ to undertake appropriate corrective action.
  327. @:PASCAL H}{\ph@>
  328. @^system dependencies@>
  329.  
  330. \TeX's file-opening procedures return |false| if no file identified by
  331. |name_of_file| could be opened.
  332.  
  333. @d reset_OK(#)==erstat(#)=0
  334. @d rewrite_OK(#)==erstat(#)=0
  335.  
  336. @p function a_open_in(var f:alpha_file):boolean;
  337.   {open a text file for input}
  338. begin reset(f,name_of_file,'/O'); a_open_in:=reset_OK(f);
  339. end;
  340. @#
  341. function a_open_out(var f:alpha_file):boolean;
  342.   {open a text file for output}
  343. begin rewrite(f,name_of_file,'/O'); a_open_out:=rewrite_OK(f);
  344. end;
  345. @#
  346. function b_open_in(var f:byte_file):boolean;
  347.   {open a binary file for input}
  348. begin reset(f,name_of_file,'/O'); b_open_in:=reset_OK(f);
  349. end;
  350. @#
  351. function b_open_out(var f:byte_file):boolean;
  352.   {open a binary file for output}
  353. begin rewrite(f,name_of_file,'/O'); b_open_out:=rewrite_OK(f);
  354. end;
  355. @#
  356. function w_open_in(var f:word_file):boolean;
  357.   {open a word file for input}
  358. begin reset(f,name_of_file,'/O'); w_open_in:=reset_OK(f);
  359. end;
  360. @#
  361. function w_open_out(var f:word_file):boolean;
  362.   {open a word file for output}
  363. begin rewrite(f,name_of_file,'/O'); w_open_out:=rewrite_OK(f);
  364. end;
  365. @y
  366. @ All of the file opening functions are defined in C.
  367. @z
  368.  
  369. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  370. % [3.28] Do file closing in C.
  371. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  372. @x
  373. @ Files can be closed with the \ph\ routine `|close(f)|', which
  374. @^system dependencies@>
  375. should be used when all input or output with respect to |f| has been completed.
  376. This makes |f| available to be opened again, if desired; and if |f| was used for
  377. output, the |close| operation makes the corresponding external file appear
  378. on the user's area, ready to be read.
  379.  
  380. These procedures should not generate error messages if a file is
  381. being closed before it has been successfully opened.
  382.  
  383. @p procedure a_close(var f:alpha_file); {close a text file}
  384. begin close(f);
  385. end;
  386. @#
  387. procedure b_close(var f:byte_file); {close a binary file}
  388. begin close(f);
  389. end;
  390. @#
  391. procedure w_close(var f:word_file); {close a word file}
  392. begin close(f);
  393. end;
  394. @y
  395. @ And all the file closing routines as well.
  396. @z
  397.  
  398. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  399. % [3.31] Do `input_ln' in C.
  400. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  401. @x
  402. @p function input_ln(var f:alpha_file;@!bypass_eoln:boolean):boolean;
  403.   {inputs the next line or returns |false|}
  404. var last_nonblank:0..buf_size; {|last| with trailing blanks removed}
  405. begin if bypass_eoln then if not eof(f) then get(f);
  406.   {input the first character of the line into |f^|}
  407. last:=first; {cf.\ Matthew 19\thinspace:\thinspace30}
  408. if eof(f) then input_ln:=false
  409. else  begin last_nonblank:=first;
  410.   while not eoln(f) do
  411.     begin if last>=max_buf_stack then
  412.       begin max_buf_stack:=last+1;
  413.       if max_buf_stack=buf_size then
  414.         @<Report overflow of the input buffer, and abort@>;
  415.       end;
  416.     buffer[last]:=xord[f^]; get(f); incr(last);
  417.     if buffer[last-1]<>" " then last_nonblank:=last;
  418.     end;
  419.   last:=last_nonblank; input_ln:=true;
  420.   end;
  421. end;
  422. @y
  423. We define |input_ln| in C, for efficiency.
  424. @z
  425.  
  426. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  427. % [3.32] `term_in' and `term_out' are standard input and output.
  428. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  429. @x
  430. @<Glob...@>=
  431. @!term_in:alpha_file; {the terminal as an input file}
  432. @!term_out:alpha_file; {the terminal as an output file}
  433. @y
  434. @d term_in==stdin {the terminal as an input file}
  435. @d term_out==stdout {the terminal as an output file}
  436. @z
  437.  
  438. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  439. % [3.33] We don't need to open terminal files.
  440. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  441. @x
  442. @ Here is how to open the terminal files
  443. in \ph. The `\.{/I}' switch suppresses the first |get|.
  444. @^system dependencies@>
  445.  
  446. @d t_open_in==reset(term_in,'TTY:','/O/I') {open the terminal for text input}
  447. @d t_open_out==rewrite(term_out,'TTY:','/O') {open the terminal for text output}
  448. @y
  449. @ Here is how to open the terminal files.  |t_open_out| does nothing.
  450. |t_open_in|, on the other hand, does the work of ``rescanning,'' or getting
  451. any command line arguments the user has provided.  It's defined in C.
  452.  
  453. @d t_open_out == {output already open for text output}
  454. @z
  455.  
  456. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  457. % [3.34] Flushing output.
  458. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  459. @x
  460. these operations can be specified in \ph:
  461. @^system dependencies@>
  462.  
  463. @d update_terminal == break(term_out) {empty the terminal output buffer}
  464. @d clear_terminal == break_in(term_in,true) {clear the terminal input buffer}
  465. @y
  466. these operations can be specified with {\mc UNIX}.  |update_terminal|
  467. does an |fflush| (via the macro |flush|). |clear_terminal| is redefined
  468. to do nothing, since the user should control the terminal.
  469. @^system dependencies@>
  470.  
  471. @d update_terminal == flush (term_out)
  472. @d clear_terminal == do_nothing
  473. @z
  474.  
  475. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  476. % [3.37] Reading the command line.
  477. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  478. @x
  479. @ The following program does the required initialization
  480. without retrieving a possible command line.
  481. It should be clear how to modify this routine to deal with command lines,
  482. if the system permits them.
  483. @^system dependencies@>
  484.  
  485. @p function init_terminal:boolean; {gets the terminal input started}
  486. label exit;
  487. begin t_open_in;
  488. loop@+begin wake_up_terminal; write(term_out,'**'); update_terminal;
  489. @.**@>
  490.   if not input_ln(term_in,true) then {this shouldn't happen}
  491.     begin write_ln(term_out);
  492.     write(term_out,'! End of file on the terminal... why?');
  493. @.End of file on the terminal@>
  494.     init_terminal:=false; return;
  495.     end;
  496.   loc:=first;
  497.   while (loc<last)and(buffer[loc]=" ") do incr(loc);
  498.   if loc<last then
  499.     begin init_terminal:=true;
  500.     return; {return unless the line was all blank}
  501.     end;
  502.   write_ln(term_out,'Please type the name of your input file.');
  503.   end;
  504. exit:end;
  505. @y
  506. @ The following program does the required initialization.
  507. Iff anything has been specified on the command line, then |t_open_in|
  508. will return with |last > first|.
  509. @^system dependencies@>
  510.  
  511. @p
  512. function init_terminal:boolean; {gets the terminal input started}
  513. label exit;
  514. begin
  515.     t_open_in;
  516.     if last > first then begin
  517.         loc := first;
  518.         while (loc < last) and (buffer[loc]=' ') do
  519.         incr(loc);
  520.         if loc < last then begin
  521.             init_terminal := true;
  522.             goto exit;
  523.         end;
  524.     end;
  525.     loop@+begin
  526.         wake_up_terminal; write(term_out, '**'); update_terminal;
  527. @.**@>
  528.         if not input_ln(term_in,true) then begin {this shouldn't happen}
  529.             write_ln(term_out);
  530.             write(term_out, '! End of file on the terminal... why?');
  531. @.End of file on the terminal@>
  532.             init_terminal:=false;
  533.         return;
  534.         end;
  535.  
  536.         loc:=first;
  537.         while (loc<last)and(buffer[loc]=" ") do
  538.             incr(loc);
  539.  
  540.         if loc<last then begin
  541.            init_terminal:=true;
  542.            return; {return unless the line was all blank}
  543.         end;
  544.         write_ln(term_out, 'Please type the name of your input file.');
  545.     end;
  546. exit:
  547. end;
  548. @z
  549.  
  550. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  551. % [4.51] Open the pool file using a path, and can't do string
  552. % assignments directly.  (`strcpy' and `strlen' work here because
  553. % `pool_name' is a constant string, and thus ends in a null and doesn't
  554. % start with a space.)
  555. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  556. @x
  557. name_of_file:=pool_name; {we needn't set |name_length|}
  558. if a_open_in(pool_file) then
  559. @y
  560. vstrcpy (name_of_file+1, pool_name); {copy the string}
  561. name_of_file[0] := ' ';
  562. name_of_file[strlen (pool_name) +1 ] := ' ';
  563. name_length := strlen (pool_name);
  564. if a_open_in (pool_file, TEX_POOL_PATH) then
  565. @z
  566.  
  567. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  568. % [4.51,52,53] Make `TEX.POOL' lowercase in messages, and change how
  569. % it's read.
  570. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  571. @x
  572. else  bad_pool('! I can''t read TEX.POOL.')
  573. @y
  574. else begin
  575.    {Like |bad_pool|, but must not close file if we never opened it}
  576.    wake_up_terminal; write_ln(term_out, '! I can''t read tex.pool.');
  577.    get_strings_started:= false; return;
  578. end
  579. @z
  580. @x
  581. begin if eof(pool_file) then bad_pool('! TEX.POOL has no check sum.');
  582. @.TEX.POOL has no check sum@>
  583. read(pool_file,m,n); {read two digits of string length}
  584. @y
  585. begin if eof(pool_file) then bad_pool('! tex.pool has no check sum.');
  586. @.TEX.POOL has no check sum@>
  587. read(pool_file,m); read(pool_file,n); {read two digits of string length}
  588. @z
  589. @x
  590.     bad_pool('! TEX.POOL line doesn''t begin with two digits.');
  591. @y
  592.     bad_pool('! tex.pool line doesn''t begin with two digits.');
  593. @z
  594. @x
  595.   bad_pool('! TEX.POOL check sum doesn''t have nine digits.');
  596. @y
  597.   bad_pool('! tex.pool check sum doesn''t have nine digits.');
  598. @z
  599. @x
  600. done: if a<>@$ then bad_pool('! TEX.POOL doesn''t match; TANGLE me again.');
  601. @y
  602. done: if a<>@$ then bad_pool('! tex.pool doesn''t match; tangle me again.');
  603. @z
  604.  
  605. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  606. % [5.61] Eliminate the misleading message ``(no format preloaded)''.
  607. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  608. @x
  609. wterm(banner);
  610. if format_ident=0 then wterm_ln(' (no format preloaded)')
  611. else  begin slow_print(format_ident); print_ln;
  612.   end;
  613. @y
  614. wterm (banner);
  615. if format_ident>0 then slow_print(format_ident); 
  616. print_ln;
  617. @z
  618.  
  619. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  620. % [6.81] Eliminate nonlocal goto, since C doesn't have them.
  621. % Plus, it's nicer just to do an exit with the appropriate status code
  622. % under Unix.  We call it `uexit' because there's a WEB symbol called
  623. % `exit' already.  We use a C macro to change `uexit' back to `exit'.
  624. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  625. @x
  626. @<Error hand...@>=
  627. procedure jump_out;
  628. begin goto end_of_TEX;
  629. end;
  630. @y
  631. @d do_final_end==begin
  632.    update_terminal;
  633.    ready_already:=0;
  634.    if (history <> spotless) and (history <> warning_issued) then
  635.        uexit(1)
  636.    else
  637.        uexit(0);
  638.    end
  639. @<Error hand...@>=
  640. procedure jump_out;
  641. begin
  642. close_files_and_terminate;
  643. do_final_end;
  644. end;
  645. @z
  646.  
  647. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  648. % [6.84] Implement the switch-to-editor option.
  649. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  650. @x
  651. line ready to be edited. But such an extension requires some system
  652. wizardry, so the present implementation simply types out the name of the
  653. file that should be
  654. edited and the relevant line number.
  655. @^system dependencies@>
  656.  
  657. There is a secret `\.D' option available when the debugging routines haven't 
  658. been commented~out.
  659. @^debugging@>
  660. @y
  661. line ready to be edited.
  662. We do this by calling the external procedure |call_edit| with a pointer to
  663. the filename, its length, and the line number.
  664. However, here we just set up the variables that will be used as arguments,
  665. since we don't want to do the switch-to-editor until after TeX has closed
  666. its files.
  667. @^system dependencies@>
  668.  
  669. There is a secret `\.D' option available when the debugging routines haven't
  670. been commented~out.
  671. @^debugging@>
  672. @d edit_file==input_stack[base_ptr]
  673. @z
  674. @x
  675. "E": if base_ptr>0 then
  676.   begin print_nl("You want to edit file ");
  677. @.You want to edit file x@>
  678.   slow_print(input_stack[base_ptr].name_field);
  679.   print(" at line "); print_int(line);
  680.   interaction:=scroll_mode; jump_out;
  681. @y
  682. "E": if base_ptr>0 then
  683.     begin
  684.     edit_name_start:=str_start[edit_file.name_field];
  685.     edit_name_length:=str_start[edit_file.name_field+1] -
  686.                   str_start[edit_file.name_field];
  687.     edit_line:=line;
  688.     jump_out;
  689. @z
  690.  
  691. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  692. % [7.104] `remainder' is a library routine on some systems, so change
  693. % its name to avoid conflicts.
  694. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  695. @x
  696. @<Glob...@>=
  697. @!arith_error:boolean; {has arithmetic overflow occurred recently?}
  698. @!remainder:scaled; {amount subtracted to get an exact division}
  699. @y
  700. @d remainder == tex_remainder
  701. @<Glob...@>=
  702. @!arith_error:boolean; {has arithmetic overflow occurred recently?}
  703. @!remainder:scaled; {amount subtracted to get an exact division}
  704. @z
  705.  
  706. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  707. % [7.109] Define glue_ratio in C.
  708. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  709. @x
  710. @!glue_ratio=real; {one-word representation of a glue expansion factor}
  711. @y
  712. @z
  713.  
  714. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  715. % [8.110] Make it easy to change constants.  Do not increase
  716. % max_quarterword without changing the memoryword structure in
  717. % `texmfmem.h'.
  718. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  719. @x
  720. @d min_quarterword=0 {smallest allowable value in a |quarterword|}
  721. @d max_quarterword=255 {largest allowable value in a |quarterword|}
  722. @d min_halfword==0 {smallest allowable value in a |halfword|}
  723. @d max_halfword==65535 {largest allowable value in a |halfword|}
  724. @y
  725. @d min_quarterword=0 {smallest allowable value in a |quarterword|}
  726. @d max_quarterword=255 {largest allowable value in a |quarterword|}
  727. @d min_halfword==0 {smallest allowable value in a |halfword|}
  728. @d max_halfword==262143 {largest allowable value in a |halfword|}
  729. @z
  730.  
  731. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  732. % [8.112] Efficiency.
  733. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  734. @x
  735. The inner loop of \TeX\ will run faster with respect to compilers
  736. that don't optimize expressions like `|x+0|' and `|x-0|', if these
  737. macros are simplified in the obvious way when |min_quarterword=0|.
  738. @^inner loop@>@^system dependencies@>
  739.  
  740. @d qi(#)==#+min_quarterword
  741.   {to put an |eight_bits| item into a quarterword}
  742. @d qo(#)==#-min_quarterword
  743.   {to take an |eight_bits| item out of a quarterword}
  744. @d hi(#)==#+min_halfword
  745.   {to put a sixteen-bit item into a halfword}
  746. @d ho(#)==#-min_halfword
  747.   {to take a sixteen-bit item from a halfword}
  748. @y
  749. The inner loop of \TeX\ will run faster with respect to compilers
  750. that don't optimize expressions like `|x+0|' and `|x-0|', if these
  751. macros are simplified in the obvious way when |min_quarterword=0|.
  752. So they have been simplified here in the obvious way.
  753. @^inner loop@>@^system dependencies@>
  754.  
  755. @d qi(#)==# {to put an |eight_bits| item into a quarterword}
  756. @d qo(#)==# {to take an |eight_bits| item from a quarterword}
  757. @d hi(#)==# {to put a sixteen-bit item into a halfword}
  758. @d ho(#)==# {to take a sixteen-bit item from a halfword}
  759. @z
  760.  
  761. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  762. % [8.113] We've put the memory structure into the include file
  763. % `texmf.h', since it's too hard to translate automatically.  Also,
  764. % remove the `word_file' type.
  765. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  766. @x
  767. @!quarterword = min_quarterword..max_quarterword; {1/4 of a word}
  768. @!halfword=min_halfword..max_halfword; {1/2 of a word}
  769. @!two_choices = 1..2; {used when there are two variants in a record}
  770. @!four_choices = 1..4; {used when there are four variants in a record}
  771. @!two_halves = packed record@;@/
  772.   @!rh:halfword;
  773.   case two_choices of
  774.   1: (@!lh:halfword);
  775.   2: (@!b0:quarterword; @!b1:quarterword);
  776.   end;
  777. @!four_quarters = packed record@;@/
  778.   @!b0:quarterword;
  779.   @!b1:quarterword;
  780.   @!b2:quarterword;
  781.   @!b3:quarterword;
  782.   end;
  783. @!memory_word = record@;@/
  784.   case four_choices of
  785.   1: (@!int:integer);
  786.   2: (@!gr:glue_ratio);
  787.   3: (@!hh:two_halves);
  788.   4: (@!qqqq:four_quarters);
  789.   end;
  790. @!word_file = file of memory_word;
  791. @y
  792. @!quarterword=min_quarterword..max_quarterword;
  793. @!halfword=min_halfword..max_halfword;
  794. @!two_choices = 1..2; {used when there are two variants in a record}
  795. @!four_choices = 1..4; {used when there are four variants in a record}
  796. @=#include "texmfmem.h";@>
  797. @z
  798.  
  799. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  800. % [9.116] Change `mem' to `zmem', so we can define mem to be a register
  801. % pointer to the memory array for speed.
  802. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  803. @x
  804. @!mem : array[mem_min..mem_max] of memory_word; {the big dynamic storage area}
  805. @y
  806. @!zmem : array[mem_min..mem_max] of memory_word; {the big dynamic storage area}
  807. @z
  808.  
  809. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  810. % [9.127] Fix casting problem in C.
  811. % There are several of these.  They come from the rules C uses for
  812. % comparing signed and unsigned quantities.  Just doing the comparison
  813. % can result in incorrect evaluation wrt the way Pascal would do it.
  814. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  815. @x
  816. if r>p+1 then @<Allocate from the top of node |p| and |goto found|@>;
  817. @y
  818. if r>toint(p+1) then @<Allocate from the top of node |p| and |goto found|@>;
  819. @z
  820.  
  821. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  822. % [11.165] Fix the word `free' so that it doesn't conflict with the
  823. % standard C library routine of the same name.
  824. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  825. @x
  826. been included. (You may want to decrease the size of |mem| while you
  827. @^debugging@>
  828. are debugging.)
  829. @y
  830. been included. (You may want to decrease the size of |mem| while you
  831. @^debugging@>
  832. are debugging.)
  833.  
  834. @d free==free_arr
  835. @z
  836.  
  837. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  838. % [12.174,176] Eliminate some unsigned comparisons to zero.
  839. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  840. @x
  841.         begin if (font(p)<font_base)or(font(p)>font_max) then
  842.           print_char("*")
  843. @y
  844.         begin if (font(p)>font_max) then
  845.           print_char("*")
  846. @z
  847.  
  848. @x
  849. @p procedure print_font_and_char(@!p:integer); {prints |char_node| data}
  850. begin if p>mem_end then print_esc("CLOBBERED.")
  851. else  begin if (font(p)<font_base)or(font(p)>font_max) then print_char("*")
  852. @y
  853. @p procedure print_font_and_char(@!p:integer); {prints |char_node| data}
  854. begin if p>mem_end then print_esc("CLOBBERED.")
  855. else  begin if (font(p)>font_max) then print_char("*")
  856. @z
  857.  
  858. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  859. % [12.186] Don't worry about strange floating point values.
  860. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  861. @x
  862.   if glue_sign(p)=shrinking then print("- ");
  863.   if abs(mem[p+glue_offset].int)<@'4000000 then print("?.?")
  864.   else if abs(g)>float_constant(20000) then
  865. @y
  866.   if glue_sign(p)=shrinking then print("- ");
  867.   { The Unix |pc| folks removed this restriction with a remark that
  868.     invalid bit patterns were vanishingly improbable, so we follow
  869.     their example without really understanding it.
  870.   |if abs(mem[p+glue_offset].int)<@'4000000 then print('?.?')|
  871.   |else| }
  872.   if fabs(g)>float_constant(20000) then
  873. @z
  874.  
  875. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  876. % [17.241] Do `fix_date_and_time' in C.
  877. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  878. @x
  879. @ The following procedure, which is called just before \TeX\ initializes its
  880. input and output, establishes the initial values of the date and time.
  881. @^system dependencies@>
  882. Since standard \PASCAL\ cannot provide such information, something special
  883. is needed. The program here simply specifies July 4, 1776, at noon; but
  884. users probably want a better approximation to the truth.
  885.  
  886. @p procedure fix_date_and_time;
  887. begin time:=12*60; {minutes since midnight}
  888. day:=4; {fourth day of the month}
  889. month:=7; {seventh month of the year}
  890. year:=1776; {Anno Domini}
  891. end;
  892. @y
  893. @ The following procedure, which is called just before \TeX\ initializes its
  894. input and output, establishes the initial values of the date and time.
  895. It calls a macro-defined |date_and_time| routine.  |date_and_time|
  896. in turn is a C macro, which calls |get_date_and_time|, passing
  897. it the addresses of the day, month, etc., so they can be set by the
  898. routine.  |get_date_and_time| also sets up interrupt catching if that
  899. is conditionally compiled in the C code.
  900. @^system dependencies@>
  901.  
  902. @d fix_date_and_time==date_and_time(time,day,month,year)
  903. @z
  904.  
  905. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  906. % [17.253] Change eqtb to zeqtb.
  907. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  908. @x
  909. @!eqtb:array[active_base..eqtb_size] of memory_word;
  910. @y
  911. @!zeqtb:array[active_base..eqtb_size] of memory_word;
  912. @z
  913.  
  914. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  915. % [18.262] Remove more unsigned comparisons to zero.
  916. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  917. @x
  918. else if (text(p)<0)or(text(p)>=str_ptr) then print_esc("NONEXISTENT.")
  919. @y
  920. else if (text(p)>=str_ptr) then print_esc("NONEXISTENT.")
  921. @z
  922.  
  923. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  924. % [29.513] Area and extension rules for filenames.
  925. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  926. @x
  927. @ The file names we shall deal with for illustrative purposes have the
  928. following structure:  If the name contains `\.>' or `\.:', the file area
  929. consists of all characters up to and including the final such character;
  930. otherwise the file area is null.  If the remaining file name contains
  931. `\..', the file extension consists of all such characters from the first
  932. remaining `\..' to the end, otherwise the file extension is null.
  933. @^system dependencies@>
  934.  
  935. We can scan such file names easily by using two global variables that keep track
  936. of the occurrences of area and extension delimiters:
  937.  
  938. @<Glob...@>=
  939. @!area_delimiter:pool_pointer; {the most recent `\.>' or `\.:', if any}
  940. @!ext_delimiter:pool_pointer; {the relevant `\..', if any}
  941. @y
  942. @ The file names we shall deal with for illustrative purposes have the
  943. following structure:  If the name contains `\./', the file area
  944. consists of all characters up to and including the final such character;
  945. otherwise the file area is null.  If the remaining file name contains
  946. `\..', the file extension consists of all such characters from the last
  947. `\..' to the end, otherwise the file extension is null.
  948. @^system dependencies@>
  949.  
  950. We can scan such file names easily by using two global variables that keep
  951. track of the occurrences of area and extension delimiters:
  952.  
  953. @<Glob...@>=
  954. @!area_delimiter:pool_pointer; {the second-most recent `\..', if any}
  955. @!ext_delimiter:pool_pointer; {the most recent `\..' or `\./', if any}
  956. @z
  957.  
  958. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  959. % [29.514] TeX area directories.
  960. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  961. @x
  962. @d TEX_area=="TeXinputs:"
  963. @.TeXinputs@>
  964. @d TEX_font_area=="TeXfonts:"
  965. @.TeXfonts@>
  966. @y
  967. In C, the default paths are specified in a separate
  968. file, \.{site.h}.  The file opening procedures do path searching
  969. based either on those default paths, or on paths given by the user
  970. in environment variables.
  971. @z
  972.  
  973. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  974. % [29.516] more_name
  975. % Modified for RISC OS by Jakob Stoklund Olesen 11. Mar 1998
  976. % Area delimiter is always 0 because we don't use TeX's write to
  977. % current directory feature. Extension delimiter is either "." or "/"
  978. % when jobname=0
  979. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  980. @x
  981. else  begin str_room(1); append_char(c); {contribute |c| to the current string}
  982.   if (c=">")or(c=":") then
  983.     begin area_delimiter:=cur_length; ext_delimiter:=0;
  984.     end
  985.   else if (c=".")and(ext_delimiter=0) then ext_delimiter:=cur_length;
  986. @y
  987. else  begin str_room(1); append_char(c); {contribute |c| to the current string}
  988.   if (c=".") or ((c="/") and (jobname=0)) then
  989.     begin ext_delimiter:=cur_length;
  990.     end;
  991. @z
  992.  
  993. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  994. % For RISC OS. In end_name ensure that the first char of the extension
  995. % is '.' if '/' was scanned.
  996. % Jakob Stoklund Olesen 11. Mar 1998
  997. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  998. %@x
  999. %  str_start[str_ptr+1]:=str_start[str_ptr]+ext_delimiter-area_delimiter-1;
  1000. %  incr(str_ptr); cur_ext:=make_string;
  1001. %  end;
  1002. %end;
  1003. %@y
  1004. %  str_start[str_ptr+1]:=str_start[str_ptr]+ext_delimiter-area_delimiter-1;
  1005. %  incr(str_ptr); cur_ext:=make_string;
  1006. %  str_pool[str_start[cur_ext]]:="."; { Change ext delimiter }
  1007. %  end;
  1008. %end;
  1009. %@z
  1010.  
  1011. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1012. % [29.519] In pack_file_name, leave room for the extra null we append at
  1013. % the end of a filename in make_c_string.
  1014. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1015. @x
  1016. if k<=file_name_size then name_length:=k@+else name_length:=file_name_size;
  1017. @y
  1018. if k<file_name_size then name_length:=k@+else name_length:=file_name_size-1;
  1019. @z
  1020.  
  1021. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1022. % [29.520] The default format.
  1023. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1024. @x
  1025. @d format_default_length=20 {length of the |TEX_format_default| string}
  1026. @d format_area_length=11 {length of its area part}
  1027. @d format_ext_length=4 {length of its `\.{.fmt}' part}
  1028. @y
  1029. Under {\mc UNIX} we don't give the area part, instead depending
  1030. on the path searching that will happen during file opening.  Also, the
  1031. length will be set in the main program.
  1032.  
  1033. @d format_area_length=0 {length of its area part}
  1034. @d format_ext_length=4 {length of its `\.{.fmt}' part}
  1035. @z
  1036.  
  1037. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1038. % [29.521] Where `plain.fmt' is.
  1039. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1040. @x
  1041. @!TEX_format_default:packed array[1..format_default_length] of char;
  1042.  
  1043. @ @<Set init...@>=
  1044. TEX_format_default:='TeXformats:plain.fmt';
  1045. @y
  1046. @!format_default_length: integer;
  1047. @!TEX_format_default: c_char_pointer;
  1048.  
  1049. @ We set the name of the default format file and the length of that name
  1050. in C, instead of Pascal, since we want them to depend on the name of the
  1051. program.
  1052. @z
  1053.  
  1054. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1055. % [29.523] Change to pack_buffered_name as with pack_file_name.
  1056. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1057. @x
  1058. if k<=file_name_size then name_length:=k@+else name_length:=file_name_size;
  1059. @y
  1060. if k<file_name_size then name_length:=k@+else name_length:=file_name_size-1;
  1061. @z
  1062.  
  1063. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1064. % [29.524] Format file opening: only try once, with path searching.
  1065. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1066. @x
  1067.   pack_buffered_name(0,loc,j-1); {try first without the system file area}
  1068.   if w_open_in(fmt_file) then goto found;
  1069.   pack_buffered_name(format_area_length,loc,j-1);
  1070.     {now try the system format file area}
  1071.   if w_open_in(fmt_file) then goto found;
  1072. @y
  1073.   pack_buffered_name(0,loc,j-1);
  1074.   if w_open_in(fmt_file) then goto found;
  1075. @z
  1076.  
  1077. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1078. % (still [29.524]) replace `PLAIN' in error messages with `default'.
  1079. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1080. @x
  1081.   wterm_ln('Sorry, I can''t find that format;',' will try PLAIN.');
  1082. @y
  1083.   wterm_ln('Sorry, I can''t find that format;',' will try the default.');
  1084. @z
  1085. @x
  1086.   wterm_ln('I can''t find the PLAIN format file!');
  1087. @.I can't find PLAIN...@>
  1088. @y
  1089.   wterm_ln('I can''t find the default format file!');
  1090. @.I can't find default format...@>
  1091. @z
  1092.  
  1093. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1094. % [29.532] `logname' is declared in <unistd.h> on some systems.
  1095. %          ARCHIMEDES: Set file type for DVI file
  1096. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1097. @x
  1098. @ Here's an example of how these conventions are used. Whenever it is time to
  1099. ship out a box of stuff, we shall use the macro |ensure_dvi_open|.
  1100.  
  1101. @d ensure_dvi_open==if output_file_name=0 then
  1102.   begin if job_name=0 then open_log_file;
  1103.   pack_job_name(".dvi");
  1104.   while not b_open_out(dvi_file) do
  1105.     prompt_file_name("file name for output",".dvi");
  1106.   output_file_name:=b_make_name_string(dvi_file);
  1107.   end
  1108.  
  1109. @y
  1110. @ Here's an example of how these conventions are used. Whenever it is time to
  1111. ship out a box of stuff, we shall use the macro |ensure_dvi_open|.
  1112.  
  1113. @d log_name == texmf_log_name
  1114.  
  1115. @d ensure_dvi_open==if output_file_name=0 then
  1116.   begin if job_name=0 then open_log_file;
  1117.   pack_job_name(".dvi");
  1118.   riscos_type:=riscos_dvitype;
  1119.   while not b_open_out(dvi_file) do
  1120.     prompt_file_name("file name for output",".dvi");
  1121.   output_file_name:=b_make_name_string(dvi_file);
  1122.   end
  1123.  
  1124. @z
  1125.  
  1126. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1127. % [29.536] Adjust for C string conventions.
  1128. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1129. @x
  1130. @!months:packed array [1..36] of char; {abbreviations of month names}
  1131. @y
  1132. @!months:c_char_pointer;
  1133. @z
  1134.  
  1135. %%%%%%%%%% ARCHIMEDES CHANGE: Call riscos_setname();
  1136. @x
  1137. while not a_open_out(log_file) do @<Try to get a different log file name@>;
  1138. @y
  1139. while not a_open_out(log_file) do @<Try to get a different log file name@>;
  1140. riscos_setname(name_of_file); {set the `current path'}
  1141. @z
  1142.  
  1143. %%% Adjust for C string conventions cont'd
  1144. @x
  1145. begin wlog(banner);
  1146. slow_print(format_ident); print("  ");
  1147. print_int(day); print_char(" ");
  1148. months:='JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
  1149. @y
  1150. begin wlog (banner);
  1151. wlog (version_string);
  1152. slow_print(format_ident); print("  ");
  1153. print_int(day); print_char(" ");
  1154. months := ' JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC';
  1155. @z
  1156.  
  1157. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1158. % [29.537] Use a path when calling a_open_in to do a \input; also, try
  1159. % to open the file with and without the `.tex' extension, regardless of
  1160. % whether the file already has an extension.  This allows filenames like
  1161. % `foo' and `foo.bar.tex', as well as `foo.tex' and `foo.bar'.
  1162. %
  1163. % RISC OS: Flag output mode to be set from input filename.
  1164. % Search order is 1) name as given. 2) with ".tex" added.
  1165. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1166. @x
  1167. if cur_ext="" then cur_ext:=".tex";
  1168. pack_cur_name;
  1169. loop@+  begin begin_file_reading; {set up |cur_file| and new level of input}
  1170.   if a_open_in(cur_file) then goto done;
  1171.   if cur_area="" then
  1172.     begin pack_file_name(cur_name,TEX_area,cur_ext);
  1173.     if a_open_in(cur_file) then goto done;
  1174.     end;
  1175. @y
  1176. { Output mode will be set from filename on disc }
  1177. if riscos_outputmode < 0 then riscos_outputmode := -1;
  1178. pack_cur_name; {Try with given extension.}
  1179. loop@+begin
  1180.   begin_file_reading; {set up |cur_file| and new level of input}
  1181.   { If there is an extension, we try that first }
  1182.   if cur_ext<>"" and a_open_in (cur_file, TEX_INPUT_PATH) then
  1183.     goto done;
  1184.  
  1185.   { We're going to add ".tex" now, but this means that cur_ext was
  1186.     really part of the filename, not just an extension. Therefore we
  1187.     move cur_ext to the end of cur_name, but only if they are adjacent
  1188.     in the string pool (as they will be after name_end) }
  1189.   if (cur_ext<>".tex") and (name_length+5<file_name_size) then begin
  1190.     name_of_file[name_length + 1] := ".";
  1191.     name_of_file[name_length + 2] := "t";
  1192.     name_of_file[name_length + 3] := "e";
  1193.     name_of_file[name_length + 4] := "x";
  1194.     name_length := name_length + 4;
  1195.     if a_open_in (cur_file, TEX_INPUT_PATH) then begin
  1196.       if cur_ext=cur_name+1 then
  1197.         str_start[cur_ext]:=str_start[cur_ext+1];
  1198.       cur_ext:=".tex";
  1199.       goto done;
  1200.     end;
  1201.     { No luck, Remove the artificial extension we've added }
  1202.     name_length := name_length - 4;
  1203.     name_of_file[name_length + 1] := " ";
  1204.   end;
  1205.  
  1206.   { Couldn't find the file.  Put |".tex"| into the filename if there was
  1207.     no extension, and then invoke an external program.
  1208.     If it succeeds, try opening the file once more.}
  1209.   if cur_ext = "" then begin
  1210.     cur_ext := ".tex";
  1211.     pack_cur_name;
  1212.   end;
  1213.   if make_tex_tex then begin
  1214.     if a_open_in (cur_file, TEX_INPUT_PATH) then goto done;
  1215.   end;
  1216. @z
  1217.  
  1218. %pack_cur_name; {Try with |".tex"|.}
  1219. %loop@+begin
  1220. %  begin_file_reading; {set up |cur_file| and new level of input}
  1221. %  {Don't add |".tex"| if it's already there,
  1222. %   if it would overflow |name_of_file|,
  1223. %   or if |"foo"| and |"foo.tex"| are really the same
  1224. %   file, because of operating-system filename length limitations (e.g.,
  1225. %   |"afourteenlongf"| and |"afourteenlongf.tex"| under System V).}
  1226. %  if (cur_ext <> ".tex") and (name_length + 5 < file_name_size)
  1227. %     and (not extension_irrelevant_p (name_of_file, 'tex'))
  1228. %  then begin
  1229. %    name_of_file[name_length + 1] := ".";
  1230. %    name_of_file[name_length + 2] := "t";
  1231. %    name_of_file[name_length + 3] := "e";
  1232. %    name_of_file[name_length + 4] := "x";
  1233. %    name_length := name_length + 4;
  1234. %  end;
  1235. %  if a_open_in (cur_file, TEX_INPUT_PATH) then goto done;
  1236. %  
  1237. %  {Try without |".tex"|.}
  1238. %  if cur_ext = ".tex" then cur_ext := "";
  1239. %  pack_cur_name;
  1240. %  if a_open_in (cur_file, TEX_INPUT_PATH) then goto done;
  1241. %  
  1242. %  {Couldn't find the file.  Put |".tex"| back into the filename if we
  1243. %   removed it, and then invoke an external program.  If it succeeds, try
  1244. %   opening the file once more.}
  1245. %  if cur_ext = "" then begin
  1246. %    cur_ext := ".tex";
  1247. %    pack_cur_name;
  1248. %  end;
  1249. %  if make_tex_tex then begin
  1250. %    if a_open_in (cur_file, TEX_INPUT_PATH) then goto done;
  1251. %  end;
  1252. %@z
  1253.  
  1254. % Knuth should fix this -- sometimes lines go over the |max_print_line|.
  1255. % I don't remember what caused this, so I'll comment this out until it
  1256. % happens again.
  1257. % @x
  1258. % if term_offset+length(name)>max_print_line-2 then print_ln
  1259. % @y
  1260. % if term_offset+length(name)>max_print_line-3 then print_ln
  1261. % @z
  1262.  
  1263. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1264. % [29.537] Get rid of return of filename to string pool.
  1265. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1266. @x
  1267. if name=str_ptr-1 then {we can conserve string pool space now}
  1268.   begin flush_string; name:=cur_name;
  1269.   end;
  1270. @y
  1271. @z
  1272.  
  1273. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1274. % [30.563] Don't use font_area's in TFM opening, and invoke an external
  1275. % program if the first open fails.
  1276. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1277. @x
  1278. file_opened:=false;
  1279. if aire="" then pack_file_name(nom,TEX_font_area,".tfm")
  1280. else pack_file_name(nom,aire,".tfm");
  1281. if not b_open_in(tfm_file) then abort;
  1282. file_opened:=true
  1283. @y
  1284. file_opened := false;
  1285. pack_file_name (nom, aire, ".tfm");
  1286. if not b_open_in(tfm_file) then begin
  1287.   if make_tex_tfm then begin
  1288.     if not b_open_in(tfm_file) then abort;
  1289.   end else
  1290.     abort;
  1291. end;
  1292. file_opened:=true
  1293. @z
  1294.  
  1295. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1296. % [30.564] Reading the tfm file.  As a special case, whenever we open a
  1297. % tfm file, we read its first byte into `tfm_temp' right away.  TeX
  1298. % looks at `fbyte' before calling `fget', so it ends up seeing every
  1299. % byte.  This is Pascal-like I/O.
  1300. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1301. @x
  1302. @d fget==get(tfm_file)
  1303. @d fbyte==tfm_file^
  1304. @y
  1305. @d fget==tfm_temp:=getc(tfm_file)
  1306. @d fbyte==tfm_temp
  1307. @z
  1308.  
  1309. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1310. % [32.597] We only want `eof' on the TFM file to be true if we
  1311. % previously had EOF, not if we're at EOF now.  This is like `feof', and
  1312. % unlike our implementation of `eof' elsewhere.
  1313. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1314. @x
  1315. if eof(tfm_file) then abort;
  1316. @y
  1317. if feof(tfm_file) then abort;
  1318. @z
  1319.  
  1320. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1321. % [32.597] write_dvi
  1322. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1323. @x
  1324. @p procedure write_dvi(@!a,@!b:dvi_index);
  1325. var k:dvi_index;
  1326. begin for k:=a to b do write(dvi_file,dvi_buf[k]);
  1327. end;
  1328. @y
  1329. In C, we use a macro to call |fwrite| or |write| directly, writing all
  1330. the bytes to be written in one shot.  Much better even than writing four
  1331. bytes at a time.
  1332. @z
  1333.  
  1334. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1335. % [38.859] Fix a casting/expression evaluation problem.
  1336. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1337. @x
  1338. if abs(fit_class-fitness(r))>1 then d:=d+adj_demerits;
  1339. @y
  1340. if abs(toint(fit_class)-toint(fitness(r)))>1 then d:=d+adj_demerits;
  1341. @z
  1342.  
  1343. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1344. % [39.875] Another casting problem.
  1345. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1346. @x
  1347. repeat if type(r)<>delta_node then
  1348.   begin line_diff:=line_number(r)-best_line;
  1349. @y
  1350. repeat if type(r)<>delta_node then
  1351.   begin line_diff:=toint(line_number(r))-toint(best_line);
  1352. @z
  1353.  
  1354. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1355. % [42.920,921,923,924] Allow larger hyphenation tries.
  1356. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1357. @x
  1358. Comparatively few different number sequences $n_0\ldots n_k$ actually occur,
  1359. since most of the |n|'s are generally zero. Therefore the number sequences
  1360. are encoded in such a way that |trie_op|$(z_k)$ is only one byte long.
  1361. If |trie_op(@t$z_k$@>)<>min_quarterword|, when $p_1\ldots p_k$ has matched
  1362. the letters in |hc[(l-k+1)..l@,]| of language |t|,
  1363. we perform all of the required operations
  1364. for this pattern by carrying out the following little program: Set
  1365. |v:=trie_op(@t$z_k$@>)|. Then set |v:=v+op_start[t]|,
  1366. |hyf[l-hyf_distance[v]]:=@tmax@>(hyf[l-hyf_distance[v]], hyf_num[v])|,
  1367. and |v:=hyf_next[v]|; repeat, if necessary, until |v=min_quarterword|.
  1368. @y
  1369. The theory that comparatively few different number sequences $n_0\ldots n_k$
  1370. actually occur, since most of the |n|'s are generally zero, seems to fail
  1371. at least for the large German hyphenation patterns.
  1372. Therefore the number sequences cannot any longer be encoded in such a way
  1373. that |trie_op|$(z_k)$ is only one byte long.
  1374. We have introduced a new constant |max_trie_op| for the maximum allowable
  1375. hyphenation operation code value; |max_trie_op| might be different for
  1376. \TeX\ and \.{INITEX} and must not exceed |max_halfword|.
  1377. An opcode will occupy a halfword if |max_trie_op| exceeds |max_quarterword|
  1378. or a quarterword otherwise.
  1379. @^system dependencies@>
  1380. If |trie_op(@t$z_k$@>)<>min_trie_op|, when $p_1\ldots p_k$ has matched
  1381. the letters in |hc[(l-k+1)..l@,]| of language |t|,
  1382. we perform all of the required operations
  1383. for this pattern by carrying out the following little program: Set
  1384. |v:=trie_op(@t$z_k$@>)|. Then set |v:=v+op_start[t]|,
  1385. |hyf[l-hyf_distance[v]]:=@tmax@>(hyf[l-hyf_distance[v]], hyf_num[v])|,
  1386. and |v:=hyf_next[v]|; repeat, if necessary, until |v=min_trie_op|.
  1387. @z
  1388. @x
  1389. @!trie_pointer=0..trie_size; {an index into |trie|}
  1390. @y
  1391. @!trie_opcode=min_trie_op..max_trie_op;  {a trie opcode}
  1392. @!trie_pointer=0..trie_size; {an index into |trie|}
  1393. @z
  1394. @x
  1395. @ @d trie_link(#)==trie[#].rh {``downward'' link in a trie}
  1396. @d trie_char(#)==trie[#].b1 {character matched at this trie location}
  1397. @d trie_op(#)==trie[#].b0 {program for hyphenation at this trie location}
  1398. @y
  1399. @ For more than 255 trie op codes, the three fields |trie_link|, |trie_char|,
  1400. and |trie_op| will no longer fit into one memory word; thus using web2c
  1401. we define |trie| as three array instead of an array of records.
  1402. The variant will be implented by reusing the opcode field later on with
  1403. another macro.
  1404. @d trie_link(#)==trie_trl[#] {``downward'' link in a trie}
  1405. @d trie_char(#)==trie_trc[#] {character matched at this trie location}
  1406. @d trie_op(#)==trie_tro[#] {program for hyphenation at this trie location}
  1407. @z
  1408. @x
  1409. @!trie:array[trie_pointer] of two_halves; {|trie_link|, |trie_char|, |trie_op|}
  1410. @y
  1411. @!trie_trl:array[trie_pointer] of halfword; {|trie_link|}
  1412. @!trie_tro:array[trie_pointer] of halfword; {|trie_op| and |trie_link|}
  1413. @!trie_trc:array[trie_pointer] of quarterword; {|trie_char|}
  1414. @z
  1415. @x
  1416. @!hyf_next:array[1..trie_op_size] of quarterword; {continuation code}
  1417. @y
  1418. @!hyf_next:array[1..trie_op_size] of trie_opcode; {continuation code}
  1419. @z
  1420. @x
  1421.     begin if trie_op(z)<>min_quarterword then
  1422. @y
  1423.     begin if trie_op(z)<>min_trie_op then
  1424. @z
  1425. @x
  1426. until v=min_quarterword;
  1427. @y
  1428. until v=min_trie_op;
  1429. @z
  1430.  
  1431. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1432. % [43.943] Larger tries, also in documentation parts.
  1433. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1434. @x
  1435. |hyf_next[@t$v^\prime$@>]=min_quarterword|.
  1436. @y
  1437. |hyf_next[@t$v^\prime$@>]=min_trie_op|.
  1438. @z
  1439. @x
  1440. $$\hbox{|@t$v^\prime$@>:=new_trie_op(0,1,min_quarterword)|,\qquad
  1441. @y
  1442. $$\hbox{|@t$v^\prime$@>:=new_trie_op(0,1,min_trie_op)|,\qquad
  1443. @z
  1444.  
  1445. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1446. % [43.943] web2c can't parse negative lower bounds in arrays.  Sorry.
  1447. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1448. @x
  1449. @!init@! trie_op_hash:array[-trie_op_size..trie_op_size] of 0..trie_op_size;
  1450. @y
  1451. @!init@! trie_op_hash:array[neg_trie_op_size..trie_op_size] of 0..trie_op_size;
  1452. @z
  1453.  
  1454. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1455. % [43.943,944] Larger hyphenation tries.
  1456. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1457. @x
  1458. @!trie_used:array[ASCII_code] of quarterword;
  1459. @y
  1460. @!trie_used:array[ASCII_code] of trie_opcode;
  1461. @z
  1462. @x
  1463. @!trie_op_val:array[1..trie_op_size] of quarterword;
  1464. @y
  1465. @!trie_op_val:array[1..trie_op_size] of trie_opcode;
  1466. @z
  1467. @x
  1468. tini
  1469. @y
  1470. tini@;
  1471. @!max_op_used:trie_opcode; {largest opcode used for any language}
  1472. @!small_op:boolean; {flag used while dumping or undumping}
  1473. @z
  1474. @x
  1475. |new_trie_op| could return |min_quarterword| (thereby simply ignoring
  1476. @y
  1477. |new_trie_op| could return |min_trie_op| (thereby simply ignoring
  1478. @z
  1479. @x
  1480. function new_trie_op(@!d,@!n:small_number;@!v:quarterword):quarterword;
  1481. label exit;
  1482. var h:-trie_op_size..trie_op_size; {trial hash location}
  1483. @!u:quarterword; {trial op code}
  1484. @y
  1485. function new_trie_op(@!d,@!n:small_number;@!v:trie_opcode):trie_opcode;
  1486. label exit;
  1487. var h:neg_trie_op_size..trie_op_size; {trial hash location}
  1488. @!u:trie_opcode; {trial op code}
  1489. @z
  1490.  
  1491. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1492. % [43.944] Another casting problem, and use |neg_trie_op_size|.
  1493. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1494. @x
  1495. begin h:=abs(n+313*d+361*v+1009*cur_lang) mod (trie_op_size+trie_op_size)
  1496.   - trie_op_size;
  1497. @y
  1498. begin h:=abs(toint(n)+313*toint(d)+361*toint(v)+1009*toint(cur_lang))
  1499.   mod (trie_op_size - neg_trie_op_size)
  1500.   + neg_trie_op_size;
  1501. @z
  1502.  
  1503. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1504. % [43.944,945,946] And larger tries again.
  1505. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1506. @x
  1507.     if u=max_quarterword then
  1508.       overflow("pattern memory ops per language",
  1509.         max_quarterword-min_quarterword);
  1510.     incr(trie_op_ptr); incr(u); trie_used[cur_lang]:=u;
  1511. @y
  1512.     if u=max_trie_op then
  1513.       overflow("pattern memory ops per language",
  1514.       max_trie_op-min_trie_op);
  1515.     incr(trie_op_ptr); incr(u); trie_used[cur_lang]:=u;
  1516.     if u>max_op_used then max_op_used:=u;
  1517. @z
  1518. @x
  1519. op_start[0]:=-min_quarterword;
  1520. @y
  1521. op_start[0]:=-min_trie_op;
  1522. @z
  1523. @x
  1524. for k:=0 to 255 do trie_used[k]:=min_quarterword;
  1525. @y
  1526. for k:=0 to 255 do trie_used[k]:=min_trie_op;
  1527. @z
  1528. @x
  1529. trie_op_ptr:=0;
  1530. @y
  1531. max_op_used:=min_trie_op;
  1532. trie_op_ptr:=0;
  1533. @z
  1534. @x
  1535. @t\hskip10pt@>@!trie_o:packed array[trie_pointer] of quarterword;
  1536. @y
  1537. @t\hskip10pt@>@!trie_o:packed array[trie_pointer] of trie_opcode;
  1538. @z
  1539.  
  1540. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1541. % [43.947] A casting problem.
  1542. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1543. @x
  1544. begin h:=abs(trie_c[p]+1009*trie_o[p]+@|
  1545.     2718*trie_l[p]+3142*trie_r[p]) mod trie_size;
  1546. @y
  1547. begin h:=abs(toint(trie_c[p])+1009*toint(trie_o[p])+@|
  1548.     2718*toint(trie_l[p])+3142*toint(trie_r[p])) mod trie_size;
  1549. @z
  1550.  
  1551. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1552. % [43.950,958,960,963] Larger tries.
  1553. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1554. @x
  1555. @d trie_back(#)==trie[#].lh {backward links in |trie| holes}
  1556. @y
  1557. @d trie_back(#)==trie_tro[#] {use the opcode field now for backward links}
  1558. @z
  1559. @x
  1560. @<Move the data into |trie|@>=
  1561. h.rh:=0; h.b0:=min_quarterword; h.b1:=min_quarterword; {|trie_link:=0|,
  1562.   |trie_op:=min_quarterword|, |trie_char:=qi(0)|}
  1563. if trie_root=0 then {no patterns were given}
  1564.   begin for r:=0 to 256 do trie[r]:=h;
  1565. @y
  1566. @d clear_trie == {clear |trie[r]|}
  1567.   begin trie_link(r):=0;
  1568.   trie_op(r):=min_trie_op;
  1569.   trie_char(r):=min_quarterword; {|trie_char:=qi(0)|}
  1570.   end
  1571. @<Move the data into |trie|@>=
  1572. if trie_root=0 then {no patterns were given}
  1573.   begin for r:=0 to 256 do clear_trie;
  1574. @z
  1575. @x
  1576.   repeat s:=trie_link(r); trie[r]:=h; r:=s;
  1577. @y
  1578.   repeat s:=trie_link(r); clear_trie; r:=s;
  1579. @z
  1580. @x
  1581. @!v:quarterword; {trie op code}
  1582. @y
  1583. @!v:trie_opcode; {trie op code}
  1584. @z
  1585. @x
  1586. if trie_o[q]<>min_quarterword then
  1587. @y
  1588. if trie_o[q]<>min_trie_op then
  1589. @z
  1590. @x
  1591. trie_c[p]:=si(c); trie_o[p]:=min_quarterword;
  1592. @y
  1593. trie_c[p]:=si(c); trie_o[p]:=min_trie_op;
  1594. @z
  1595. @x
  1596. l:=k; v:=min_quarterword;
  1597. @y
  1598. l:=k; v:=min_trie_op;
  1599. @z
  1600. @x
  1601. @!h:two_halves; {template used to zero out |trie|'s holes}
  1602. @y
  1603. @z
  1604.  
  1605. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1606. % [49.1275] Same stuff as for \input, this time for \openin.
  1607. % RISC OS: Modified to try with given extension first. We don't go
  1608. % through the same trouble of making cur_name correct as it isn't
  1609. % used for anything
  1610. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1611. @x
  1612.   if cur_ext="" then cur_ext:=".tex";
  1613.   pack_cur_name;
  1614.   if a_open_in(read_file[n]) then read_open[n]:=just_open;
  1615. @y
  1616.   pack_cur_name; {Try with given ext.}
  1617.   if (cur_ext <> "") and a_open_in (read_file[n], TEX_INPUT_PATH) then
  1618.     read_open[n] := just_open
  1619.   else begin
  1620.     if name_length + 5 < file_name_size then begin
  1621.       name_of_file[name_length + 1] := ".";
  1622.       name_of_file[name_length + 2] := "t";
  1623.       name_of_file[name_length + 3] := "e";
  1624.       name_of_file[name_length + 4] := "x";
  1625.       name_length := name_length + 4;
  1626.       if a_open_in (read_file[n], TEX_INPUT_PATH) then
  1627.         read_open[n] := just_open
  1628.       else begin
  1629.         name_length := name_length - 4;
  1630.         name_of_file[name_length + 1] := " ";
  1631.       end;
  1632.     end;
  1633.   end;
  1634. @z
  1635.  
  1636. %  pack_cur_name; {Try with |".tex"|.}
  1637. %  if (cur_ext <> ".tex") and (name_length + 5 < file_name_size)
  1638. %     and (not extension_irrelevant_p (name_of_file, 'tex'))
  1639. %  then begin
  1640. %    name_of_file[name_length + 1] := ".";
  1641. %    name_of_file[name_length + 2] := "t";
  1642. %    name_of_file[name_length + 3] := "e";
  1643. %    name_of_file[name_length + 4] := "x";
  1644. %    name_length := name_length + 4;
  1645. %  end;
  1646. %  if a_open_in (read_file[n], TEX_INPUT_PATH)
  1647. %  then read_open[n] := just_open
  1648. %  else begin
  1649. %    if cur_ext = ".tex" then cur_ext := "";
  1650. %    pack_cur_name; {Try without |".tex"|.}
  1651. %    if a_open_in (read_file[n], TEX_INPUT_PATH)
  1652. %    then read_open[n] := just_open;
  1653. %  end;
  1654. %@z
  1655.  
  1656. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1657. % [50.1302] Eliminate now-unused variable `w' in `store_fmt_file'.
  1658. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1659. @x
  1660. @!x: integer; {something to dump}
  1661. @!w: four_quarters; {four ASCII codes}
  1662. @y
  1663. @!x: integer; {something to dump}
  1664. @z
  1665.  
  1666. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1667. % [50.1303] Ditto, for `load_fmt_file'.
  1668. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1669. @x
  1670. @!x: integer; {something undumped}
  1671. @!w: four_quarters; {four ASCII codes}
  1672. @y
  1673. @!x: integer; {something undumped}
  1674. @z
  1675.  
  1676. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1677. % [50.??] Do reading and writing of `fmt_file' in C.
  1678. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1679. @x
  1680. @d dump_wd(#)==begin fmt_file^:=#; put(fmt_file);@+end
  1681. @d dump_int(#)==begin fmt_file^.int:=#; put(fmt_file);@+end
  1682. @d dump_hh(#)==begin fmt_file^.hh:=#; put(fmt_file);@+end
  1683. @d dump_qqqq(#)==begin fmt_file^.qqqq:=#; put(fmt_file);@+end
  1684. @y
  1685. @z
  1686.  
  1687. @x
  1688. @d undump_wd(#)==begin get(fmt_file); #:=fmt_file^;@+end
  1689. @d undump_int(#)==begin get(fmt_file); #:=fmt_file^.int;@+end
  1690. @d undump_hh(#)==begin get(fmt_file); #:=fmt_file^.hh;@+end
  1691. @d undump_qqqq(#)==begin get(fmt_file); #:=fmt_file^.qqqq;@+end
  1692. @y
  1693. @z
  1694.  
  1695. @x
  1696. x:=fmt_file^.int;
  1697. @y
  1698. undump_int(x);        {This reads the first word of the \.{.fmt} file}
  1699. @z
  1700.  
  1701. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1702. % [??] Make dumping/undumping more efficient.
  1703. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1704. @x
  1705. for k:=0 to str_ptr do dump_int(str_start[k]);
  1706. k:=0;
  1707. while k+4<pool_ptr do
  1708.   begin dump_four_ASCII; k:=k+4;
  1709.   end;
  1710. k:=pool_ptr-4; dump_four_ASCII;
  1711. @y
  1712. dump_things(str_start[0], str_ptr+1);
  1713. dump_things(str_pool[0], pool_ptr);
  1714. @z
  1715.  
  1716. @x
  1717. for k:=0 to str_ptr do undump(0)(pool_ptr)(str_start[k]);
  1718. k:=0;
  1719. while k+4<pool_ptr do
  1720.   begin undump_four_ASCII; k:=k+4;
  1721.   end;
  1722. k:=pool_ptr-4; undump_four_ASCII;
  1723. @y
  1724. undump_things(str_start[0], str_ptr+1);
  1725. undump_things(str_pool[0], pool_ptr);
  1726. @z
  1727.  
  1728. @x
  1729. repeat for k:=p to q+1 do dump_wd(mem[k]);
  1730. x:=x+q+2-p; var_used:=var_used+q-p;
  1731. p:=q+node_size(q); q:=rlink(q);
  1732. until q=rover;
  1733. var_used:=var_used+lo_mem_max-p; dyn_used:=mem_end+1-hi_mem_min;@/
  1734. for k:=p to lo_mem_max do dump_wd(mem[k]);
  1735. x:=x+lo_mem_max+1-p;
  1736. dump_int(hi_mem_min); dump_int(avail);
  1737. for k:=hi_mem_min to mem_end do dump_wd(mem[k]);
  1738. @y
  1739. repeat
  1740.  dump_things(mem[p], q+2-p);
  1741. x:=x+q+2-p; var_used:=var_used+q-p;
  1742. p:=q+node_size(q); q:=rlink(q);
  1743. until q=rover;
  1744. var_used:=var_used+lo_mem_max-p; dyn_used:=mem_end+1-hi_mem_min;@/
  1745. dump_things(mem[p], lo_mem_max+1-p);
  1746. x:=x+lo_mem_max+1-p;
  1747. dump_int(hi_mem_min); dump_int(avail);
  1748. dump_things(mem[hi_mem_min], mem_end+1-hi_mem_min);
  1749. @z
  1750.  
  1751. @x
  1752. repeat for k:=p to q+1 do undump_wd(mem[k]);
  1753. p:=q+node_size(q);
  1754. if (p>lo_mem_max)or((q>=rlink(q))and(rlink(q)<>rover)) then goto bad_fmt;
  1755. q:=rlink(q);
  1756. until q=rover;
  1757. for k:=p to lo_mem_max do undump_wd(mem[k]);
  1758. @y
  1759. repeat
  1760.   undump_things(mem[p], q+2-p);
  1761. p:=q+node_size(q);
  1762. if (p>lo_mem_max)or((q>=rlink(q))and(rlink(q)<>rover)) then goto bad_fmt;
  1763. q:=rlink(q);
  1764. until q=rover;
  1765. undump_things(mem[p], lo_mem_max+1-p);
  1766. @z
  1767.  
  1768. @x
  1769. for k:=hi_mem_min to mem_end do undump_wd(mem[k]);
  1770. @y
  1771. undump_things(mem[hi_mem_min], mem_end+1-hi_mem_min);
  1772. @z
  1773.  
  1774. @x
  1775. while k<l do
  1776.   begin dump_wd(eqtb[k]); incr(k);
  1777.   end;
  1778. @y
  1779. dump_things(eqtb[k], l-k);
  1780. @z
  1781.  
  1782. @x
  1783. while k<l do
  1784.   begin dump_wd(eqtb[k]); incr(k);
  1785.   end;
  1786. @y
  1787. dump_things(eqtb[k], l-k);
  1788. @z
  1789.  
  1790. @x
  1791. for j:=k to k+x-1 do undump_wd(eqtb[j]);
  1792. @y
  1793. undump_things(eqtb[k], x);
  1794. @z
  1795.  
  1796. @x
  1797. for p:=hash_used+1 to undefined_control_sequence-1 do dump_hh(hash[p]);
  1798. @y
  1799. dump_things(hash[hash_used+1], undefined_control_sequence-1-hash_used);
  1800. @z
  1801.  
  1802. @x
  1803. for p:=hash_used+1 to undefined_control_sequence-1 do undump_hh(hash[p]);
  1804. @y
  1805. undump_things(hash[hash_used+1], undefined_control_sequence-1-hash_used);
  1806. @z
  1807.  
  1808. @x
  1809. for k:=0 to fmem_ptr-1 do dump_wd(font_info[k]);
  1810. dump_int(font_ptr);
  1811. for k:=null_font to font_ptr do
  1812.   @<Dump the array info for internal font number |k|@>;
  1813. @y
  1814. @<Dump the array info for internal font number |k|@>;
  1815. @z
  1816.  
  1817. @x
  1818. for k:=0 to fmem_ptr-1 do undump_wd(font_info[k]);
  1819. undump_size(font_base)(font_max)('font max')(font_ptr);
  1820. for k:=null_font to font_ptr do
  1821.   @<Undump the array info for internal font number |k|@>
  1822. @y
  1823. @<Undump the array info for internal font number |k|@>;
  1824. @z
  1825.  
  1826. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1827. % [50.1322] Writing font info (almost at end of dump stuff).
  1828. % Knuth's code writes all the information relevant to a single font
  1829. % in the same section of the fmt file.  But it's a lot faster to
  1830. % write the arrays of information out, one whole array at a time.
  1831. % So that's the way we handle dumping and undumping font info.
  1832. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1833. @x
  1834. @ @<Dump the array info for internal font number |k|@>=
  1835. begin dump_qqqq(font_check[k]);
  1836. dump_int(font_size[k]);
  1837. dump_int(font_dsize[k]);
  1838. dump_int(font_params[k]);@/
  1839. dump_int(hyphen_char[k]);
  1840. dump_int(skew_char[k]);@/
  1841. dump_int(font_name[k]);
  1842. dump_int(font_area[k]);@/
  1843. dump_int(font_bc[k]);
  1844. dump_int(font_ec[k]);@/
  1845. dump_int(char_base[k]);
  1846. dump_int(width_base[k]);
  1847. dump_int(height_base[k]);@/
  1848. dump_int(depth_base[k]);
  1849. dump_int(italic_base[k]);
  1850. dump_int(lig_kern_base[k]);@/
  1851. dump_int(kern_base[k]);
  1852. dump_int(exten_base[k]);
  1853. dump_int(param_base[k]);@/
  1854. dump_int(font_glue[k]);@/
  1855. dump_int(bchar_label[k]);
  1856. dump_int(font_bchar[k]);
  1857. dump_int(font_false_bchar[k]);@/
  1858. print_nl("\font"); print_esc(font_id_text(k)); print_char("=");
  1859. print_file_name(font_name[k],font_area[k],"");
  1860. if font_size[k]<>font_dsize[k] then
  1861.   begin print(" at "); print_scaled(font_size[k]); print("pt");
  1862.   end;
  1863. end
  1864. @y
  1865. @ @<Dump the array info for internal font number |k|@>=
  1866. begin dump_things(font_info[0], fmem_ptr);
  1867. dump_int(font_ptr);
  1868. dump_things(font_check[null_font], font_ptr+1-null_font);
  1869. dump_things(font_size[null_font], font_ptr+1-null_font);
  1870. dump_things(font_dsize[null_font], font_ptr+1-null_font);
  1871. dump_things(font_params[null_font], font_ptr+1-null_font);
  1872. dump_things(hyphen_char[null_font], font_ptr+1-null_font);
  1873. dump_things(skew_char[null_font], font_ptr+1-null_font);
  1874. dump_things(font_name[null_font], font_ptr+1-null_font);
  1875. dump_things(font_area[null_font], font_ptr+1-null_font);
  1876. dump_things(font_bc[null_font], font_ptr+1-null_font);
  1877. dump_things(font_ec[null_font], font_ptr+1-null_font);
  1878. dump_things(char_base[null_font], font_ptr+1-null_font);
  1879. dump_things(width_base[null_font], font_ptr+1-null_font);
  1880. dump_things(height_base[null_font], font_ptr+1-null_font);
  1881. dump_things(depth_base[null_font], font_ptr+1-null_font);
  1882. dump_things(italic_base[null_font], font_ptr+1-null_font);
  1883. dump_things(lig_kern_base[null_font], font_ptr+1-null_font);
  1884. dump_things(kern_base[null_font], font_ptr+1-null_font);
  1885. dump_things(exten_base[null_font], font_ptr+1-null_font);
  1886. dump_things(param_base[null_font], font_ptr+1-null_font);
  1887. dump_things(font_glue[null_font], font_ptr+1-null_font);
  1888. dump_things(bchar_label[null_font], font_ptr+1-null_font);
  1889. dump_things(font_bchar[null_font], font_ptr+1-null_font);
  1890. dump_things(font_false_bchar[null_font], font_ptr+1-null_font);
  1891. for k:=null_font to font_ptr do begin
  1892.   print_nl("\font"); print_esc(font_id_text(k)); print_char("=");
  1893.   print_file_name(font_name[k],font_area[k],"");
  1894.   if font_size[k]<>font_dsize[k] then begin
  1895.     print(" at "); print_scaled(font_size[k]); print("pt");
  1896.   end;
  1897. end;
  1898. end
  1899. @z
  1900.  
  1901. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1902. % [50.1322] Reading font info for C (nearly done with undump stuff).
  1903. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  1904. @x
  1905. @ @<Undump the array info for internal font number |k|@>=
  1906. begin undump_qqqq(font_check[k]);@/
  1907. undump_int(font_size[k]);
  1908. undump_int(font_dsize[k]);
  1909. undump(min_halfword)(max_halfword)(font_params[k]);@/
  1910. undump_int(hyphen_char[k]);
  1911. undump_int(skew_char[k]);@/
  1912. undump(0)(str_ptr)(font_name[k]);
  1913. undump(0)(str_ptr)(font_area[k]);@/
  1914. undump(0)(255)(font_bc[k]);
  1915. undump(0)(255)(font_ec[k]);@/
  1916. undump_int(char_base[k]);
  1917. undump_int(width_base[k]);
  1918. undump_int(height_base[k]);@/
  1919. undump_int(depth_base[k]);
  1920. undump_int(italic_base[k]);
  1921. undump_int(lig_kern_base[k]);@/
  1922. undump_int(kern_base[k]);
  1923. undump_int(exten_base[k]);
  1924. undump_int(param_base[k]);@/
  1925. undump(min_halfword)(lo_mem_max)(font_glue[k]);@/
  1926. undump(0)(fmem_ptr-1)(bchar_label[k]);
  1927. undump(min_quarterword)(non_char)(font_bchar[k]);
  1928. undump(min_quarterword)(non_char)(font_false_bchar[k]);
  1929. end
  1930. @y
  1931. @  The way this is done in C makes the reference to
  1932. the internal font number meaningless, but putting the code
  1933. here preserves the association with the WEB modules.
  1934.  
  1935. @<Undump the array info for internal font number |k|@>=
  1936. begin undump_things(font_info[0], fmem_ptr);
  1937. undump_size(font_base)(font_max)('font max')(font_ptr);
  1938. undump_things(font_check[null_font], font_ptr+1-null_font);
  1939. undump_things(font_size[null_font], font_ptr+1-null_font);
  1940. undump_things(font_dsize[null_font], font_ptr+1-null_font);
  1941. undump_things(font_params[null_font], font_ptr+1-null_font);
  1942. undump_things(hyphen_char[null_font], font_ptr+1-null_font);
  1943. undump_things(skew_char[null_font], font_ptr+1-null_font);
  1944. undump_things(font_name[null_font], font_ptr+1-null_font);
  1945. undump_things(font_area[null_font], font_ptr+1-null_font);
  1946. undump_things(font_bc[null_font], font_ptr+1-null_font);
  1947. undump_things(font_ec[null_font], font_ptr+1-null_font);
  1948. undump_things(char_base[null_font], font_ptr+1-null_font);
  1949. undump_things(width_base[null_font], font_ptr+1-null_font);
  1950. undump_things(height_base[null_font], font_ptr+1-null_font);
  1951. undump_things(depth_base[null_font], font_ptr+1-null_font);
  1952. undump_things(italic_base[null_font], font_ptr+1-null_font);
  1953. undump_things(lig_kern_base[null_font], font_ptr+1-null_font);
  1954. undump_things(kern_base[null_font], font_ptr+1-null_font);
  1955. undump_things(exten_base[null_font], font_ptr+1-null_font);
  1956. undump_things(param_base[null_font], font_ptr+1-null_font);
  1957. undump_things(font_glue[null_font], font_ptr+1-null_font);
  1958. undump_things(bchar_label[null_font], font_ptr+1-null_font);
  1959. undump_things(font_bchar[null_font], font_ptr+1-null_font);
  1960. undump_things(font_false_bchar[null_font], font_ptr+1-null_font);
  1961. end
  1962. @z
  1963.  
  1964. % The hyphenation patterns.
  1965. @x
  1966. for k:=0 to trie_max do dump_hh(trie[k]);
  1967. dump_int(trie_op_ptr);
  1968. for k:=1 to trie_op_ptr do
  1969.   begin dump_int(hyf_distance[k]);
  1970.   dump_int(hyf_num[k]);
  1971.   dump_int(hyf_next[k]);
  1972.   end;
  1973. @y
  1974. dump_things(trie_trl[0], trie_max+1);
  1975. dump_things(trie_tro[0], trie_max+1);
  1976. dump_things(trie_trc[0], trie_max+1);
  1977. dump_int(trie_op_ptr);
  1978. dump_things(hyf_distance[1], trie_op_ptr);
  1979. dump_things(hyf_num[1], trie_op_ptr);
  1980. dump_things(hyf_next[1], trie_op_ptr);
  1981. @z
  1982.  
  1983. @x
  1984. for k:=0 to j do undump_hh(trie[k]);
  1985. undump_size(0)(trie_op_size)('trie op size')(j); @+init trie_op_ptr:=j;@+tini
  1986. for k:=1 to j do
  1987.   begin undump(0)(63)(hyf_distance[k]); {a |small_number|}
  1988.   undump(0)(63)(hyf_num[k]);
  1989.   undump(min_quarterword)(max_quarterword)(hyf_next[k]);
  1990.   end;
  1991. @y
  1992. undump_things(trie_trl[0], j+1);
  1993. undump_things(trie_tro[0], j+1);
  1994. undump_things(trie_trc[0], j+1);
  1995. undump_size(0)(trie_op_size)('trie op size')(j); @+init trie_op_ptr:=j;@+tini
  1996. undump_things(hyf_distance[1], j);
  1997. undump_things(hyf_num[1], j);
  1998. undump_things(hyf_next[1], j);
  1999. @z
  2000.  
  2001. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2002. % [50.1327] As with TFM files, `eof' here means `have we previously
  2003. % encountered the end-of-file', not `are we at the end of the file'.
  2004. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2005. @x
  2006. if (x<>69069)or eof(fmt_file) then goto bad_fmt
  2007. @y
  2008. if (x<>69069)or feof(fmt_file) then goto bad_fmt
  2009. @z
  2010.  
  2011. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2012. % [50.1328] Eliminate possibly wrong word `preloaded' from format_idents.
  2013. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2014. @x
  2015. print(" (preloaded format="); print(job_name); print_char(" ");
  2016. @y
  2017. print(" (format="); print(job_name); print_char(" ");
  2018. @z
  2019.  
  2020. % RISC OS: Type dumps as data
  2021. @x
  2022. while not w_open_out(fmt_file) do
  2023. @y
  2024. riscos_type:=riscos_dumptype;
  2025. while not w_open_out(fmt_file) do
  2026. @z
  2027.  
  2028.  
  2029. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2030. % [51.1332] `uexit' argument depends on `history'; add call to
  2031. % set_paths; make the main program a procedure, so that uses of `eqtb'
  2032. % will work.
  2033. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2034. @x
  2035. @p begin @!{|start_here|}
  2036. @y
  2037. @p procedure tex_body;
  2038. begin @!{|start_here|}
  2039. @z
  2040.  
  2041. @x
  2042. t_open_out; {open the terminal for output}
  2043. @y
  2044. t_open_out; {open the terminal for output}
  2045. {get default file paths from the environment}
  2046. set_paths (TEX_FORMAT_PATH_BIT + TEX_INPUT_PATH_BIT + TEX_POOL_PATH_BIT
  2047.            + TFM_FILE_PATH_BIT);
  2048. @z
  2049.  
  2050. @x
  2051. end_of_TEX: close_files_and_terminate;
  2052. final_end: ready_already:=0;
  2053. end.
  2054. @y
  2055. close_files_and_terminate;
  2056. final_end: do_final_end;
  2057. end {|tex_body|};
  2058. @z
  2059.  
  2060. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2061. % [51.1333] Print new line before termination; switch to editor if
  2062. % necessary.
  2063. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2064. @x
  2065.     slow_print(log_name); print_char(".");
  2066.     end;
  2067.   end;
  2068. @y
  2069.     slow_print(log_name); print_char(".");
  2070.     end;
  2071.   end;
  2072. print_ln;
  2073. if (edit_name_start<>0) and (interaction>batch_mode) then
  2074.     call_edit(str_pool,edit_name_start,edit_name_length,edit_line);
  2075. @z
  2076.  
  2077. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2078. % [52.1338] Core-dump in debugging mode on 0 input.  Under Unix, it's
  2079. % not possible to switch into the debugger while a program is running.
  2080. % The best approximation is to do a core dump, then run the debugger on
  2081. % it later.
  2082. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2083. @x
  2084.     begin goto breakpoint;@\ {go to every label at least once}
  2085.     breakpoint: m:=0; @{'BREAKPOINT'@}@\
  2086.     end
  2087. @y
  2088.     dump_core {Do something to cause a core dump}
  2089. @z
  2090.  
  2091. %%%%%%%%% ARCHIMEDES CHANGE: set riscostype
  2092. @x
  2093.       pack_cur_name;
  2094.       while not a_open_out(write_file[j]) do
  2095.         prompt_file_name("output file name",".tex");
  2096.       write_open[j]:=true;
  2097. @y
  2098.       pack_cur_name;
  2099.       riscos_type:=riscos_textype;
  2100.       while not a_open_out(write_file[j]) do
  2101.         prompt_file_name("output file name",".tex");
  2102.       write_open[j]:=true;
  2103. @z
  2104.  
  2105. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2106. % [54.1376] Add editor-switch variables to globals.
  2107. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2108. @x
  2109. This section should be replaced, if necessary, by any special
  2110. modifications of the program
  2111. that are necessary to make \TeX\ work at a particular installation.
  2112. It is usually best to design your change file so that all changes to
  2113. previous sections preserve the section numbering; then everybody's version
  2114. will be consistent with the published program. More extensive changes,
  2115. which introduce new sections, can be inserted here; then only the index
  2116. itself will get a new section number.
  2117. @^system dependencies@>
  2118. @y
  2119. Here is a temporary integer, used as a holder during reading and writing of
  2120. TFM files, and a temporary memory_word, used in reading/writing format
  2121. files.
  2122. Also, the variables used to hold ``switch-to-editor'' information.
  2123. @^<system dependencies@>
  2124.  
  2125. @<Glob...@>=
  2126. @!edit_name_start: pool_pointer;
  2127. @!edit_name_length,@!edit_line,@!tfm_temp: integer;
  2128.  
  2129. @ The |edit_name_start| will be set to point into |str_pool| somewhere after
  2130. its beginning if \TeX\ is supposed to switch to an editor on exit.
  2131.  
  2132. @<Set init...@>=
  2133. edit_name_start:=0;
  2134. @z
  2135.